<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

<html>
<head>
    <title>登录页</title>
    <%--echart线图、柱状图、饼图等各种图型库 cdn--%>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/echarts/5.4.3/echarts.min.js"></script>
    <%--jquery cdn--%>
    <script type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.js"></script>
</head>
<body>
${error}
<form action="/add.do" method="post" enctype="multipart/form-data">
    名称 <input name="name" ><br>
    地址 <input name="address" ><br>

    楼盘图片 <input type="file" name="picFile"><br>
    省 <select onchange="getCity()" name="provinceId">
    <option value="">请选择</option>
    <c:forEach items="${provinceList}" var="p">
        <option     value="${p.id}">${p.name}</option>
    </c:forEach>
</select><br>
    市 <select name="cityId">
    <option value="">请选择</option>
</select><br>

    区<select name="qu">
        <option value="">请选择</option>
        <option value="东城区">东城区</option>
        <option value="西城区">西城区</option>
</select><br>


<input type="submit" value="添加"><br>

</form>

<script>

    function getCity() {

        let provinceId = $('[name=provinceId]').val(); //  省份id

        $.ajax({
            url: 'getCity.do?provinceId=' + provinceId,
            success: function (res) {
                console.log(res)

                $('[name=cityId]').empty();  // 清空城市的下拉框

                $('[name=cityId]').append('<option value="">请选择</option>')

                for (let x of res) { // 遍历城市
                    $('[name=cityId]').append('<option value=' + x.id + '>' + x.name + '</option>')
                }
                $('[name=cityId]').val(${query.cityId})
            }
        })

    }
</script>

</body>
</html>